package com.ting.test.algorithms.inta;

/**
 * Created by 雷霆 on 2020/4/14.
 * <p>
 * Description：
 */
public class IntegerReversal {

    private static int test1(Integer num) {

        if (num == Integer.MIN_VALUE) {
            return 0;
        }
        int flag = num < 0 ? -1 : 1;
        num = num * flag;
        int result = 0;
        int temp = 0;
        while (num > 0) {
            temp = result;
            result += num % 10;
            result = result * 10;
            num = num / 10;
            //如果不发生溢出，则result/10一定等于temp
            //注意 溢出不会抛异常
            if (result / 10 != temp) {
                return 0;
            }

        }
        return result * flag;
    }

    public static void main(String[] args) {
        test1(123);
    }
}
